package com.wowoai.utils;

import com.alibaba.fastjson.JSONObject;
import com.wowoai.common.userInfo.UserInfo;
import com.wowoai.common.userInfo.UserInfoCovert;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class Base64Util {

    public static UserInfo decrypt(String token){
        //Base64解码
        byte[] decodedBytes = Base64.getDecoder().decode(token);
        String decodedString = new String(decodedBytes, StandardCharsets.UTF_8);
        UserInfoCovert userInfoCovert = JSONObject.parseObject(decodedString, UserInfoCovert.class);
        UserInfo userInfo = new UserInfo();
        userInfo.setUserId(Long.parseLong(userInfoCovert.getId()));
        userInfo.setUserName(userInfoCovert.getNickName());
        userInfo.setPhoneNumber(userInfoCovert.getPhoneNumber());
        return userInfo;
    }
}
